import React, { useEffect, useState } from 'react'
import { getUserInfo } from '../../api/user'
import { Table, Space, Button, Switch } from 'antd'

const columns = [
  {
    title: '用户名',
    dataIndex: 'name'
  },
  {
    title: '用户账号',
    dataIndex: 'account'
  },
  {
    title: '创建时间',
    dataIndex: 'createAt'
  },
  {
    title: '用户密钥',
    dataIndex: 'guid'
  },
  // {
  //   title: 'Tags',
  //   key: 'tags',
  //   dataIndex: 'tags',
  //   render: tags => (
  //     <>
  //       {tags.map(tag => {
  //         let color = tag.length > 5 ? 'geekblue' : 'green'
  //         if (tag === 'loser') {
  //           color = 'volcano'
  //         }
  //         return (
  //           <Tag color={color} key={tag}>
  //             {tag.toUpperCase()}
  //           </Tag>
  //         )
  //       })}
  //     </>
  //   )
  // },
  {
    title: '账号是否冻结',
    dataIndex: 'status',
    key: 'id',
    render: text => {
      const { status } = text

      return (
        <Switch
          checkedChildren="正常"
          unCheckedChildren="冻结"
          defaultChecked={status}
        />
      )
    }
  }
]

export default function UserOnoff() {
  const [data, setData] = useState([])
  const [loading, setLoading] = useState(false)
  useEffect(() => {
    setLoading(true)
    getUserInfo().then(res => {
      setData(res.list)
      setLoading(false)
    })
  }, [])
  return (
    <Table
      columns={columns}
      loading={loading}
      rowKey="guid"
      dataSource={data}
    />
  )
}
